package com.qinggeng.framework.manager;

import java.util.TimerTask;
import java.util.concurrent.*;

import com.qinggeng.common.utils.Threads;
import com.qinggeng.common.utils.spring.SpringUtils;

/**
 * 异步任务管理器
 *
 * @author qinggeng
 */
public class AsyncManager
{
    /**
     * 操作延迟10毫秒
     */
    private final int OPERATE_DELAY_TIME = 10;

    /**
     * 核心线程数
     */
    private final int CORE = 10;


    /**
     * 核心线程数
     */
    private final int MAXIMUMTHREAD= 20;
    /**
     * 异步操作任务调度线程池
     * new ThreadPoolExecutor(CORE, MAXIMUMTHREAD,
     *             0L, TimeUnit.MILLISECONDS,
     *             new LinkedBlockingQueue<Runnable>());
     */

    /**
     * 单例模式
     */
    private AsyncManager(){}

    private static AsyncManager me = new AsyncManager();

    public static AsyncManager me()
    {
        return me;
    }

    /**
     * 执行任务
     * 
     * @param task 任务
     */
    public void execute(TimerTask task)
    {
         ScheduledExecutorService executor =new ScheduledThreadPoolExecutor(CORE);
         executor.schedule(task, OPERATE_DELAY_TIME, TimeUnit.MILLISECONDS);
         executor.shutdown();
    }

   
}
